package com.dzm.demo.myshop.web.api.web.controller.v1;

import com.dzm.demo.myshop.commons.dto.BaseResult;
import com.dzm.demo.myshop.domain.TbUser;
import com.dzm.demo.myshop.web.api.service.TbUserService;
import com.dzm.demo.myshop.web.api.web.dto.TbUserDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 会员管理
 *@author:LeoDang
 *@date:2019/7/21
 *@version 1.0.0
 */
@RestController
@RequestMapping(value = "${api.path.v1}/users")
public class TbUserController {

    @Autowired
    private TbUserService tbUserService;

    @RequestMapping(value = "login",method = RequestMethod.POST)
    public BaseResult login(TbUser tbUser){
        TbUser user = tbUserService.login(tbUser);
        if (user == null){
            return BaseResult.fail("账号密码错误");
        }else {
            TbUserDTO tbUserDTO = new TbUserDTO();
            BeanUtils.copyProperties(user,tbUserDTO);
            return BaseResult.success("成功",tbUserDTO);
        }

}
}
